package com.composite.demo1.impl;

import java.util.ArrayList;
import java.util.List;

import com.composite.demo1.Company;

/**
 * Composite 定义有枝节点行为，用来存储子部件，在Component接口中实现与子部件有关操作，如增加(add)和删除(remove)等。
 *
 * @author Administrator
 *
 */
public class ConcreteCompany extends Company {

	private List<Company> cList;

	public ConcreteCompany() {
		cList = new ArrayList<Company>();
	}

	public ConcreteCompany(String name) {
		super(name);
		cList = new ArrayList<Company>();
	}

	@Override
	public void add(Company company) {
		cList.add(company);
	}

	@Override
	public void display(int depth) {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder("");
		for (int i = 0; i < depth; i++) {
			sb.append("-");
		}
		System.out.println(new String(sb) + this.getName());
		for (Company c : cList) {
			c.display(depth + 2);
		}
	}

	@Override
	public void romove(Company company) {
		cList.remove(company);
	}

}
